package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.result.R;
import com.atguigu.srb.core.service.LendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/core/lend")
@Api(tags = "标的管理")
@Slf4j
public class AdminLendController {
    @Autowired
    private LendService lendService;

    @ApiOperation("标的列表")
    @GetMapping("/list")
    public R getLendList() {
        List<Lend> lendList = lendService.getLendList();
        return R.ok().data("list", lendList);
    }

    @ApiOperation("标的详情")
    @GetMapping("/show/{lendId}")
    public R show(@PathVariable("lendId") Long lendId) {
        Map<String, Object> lendDetail = lendService.getLendDetail(lendId);
        return R.ok().data("lendDetail", lendDetail);
    }

    @ApiOperation("管理平台放款")
    @GetMapping("makeLoad/{lendId}")
    public R agreeAccountLend(@PathVariable("lendId") Long lendId) {

        log.info("管理平台放款--->>>流程开始");
        lendService.agreeAccountLend(lendId);
        return R.ok().message("放款成功!");
    }

}
